#include <iostream>
#include <queue>
#include <stack>

using namespace std;

void Solution()
{
    queue<int> player1;
    queue<int> player2;
    stack<int> gamepool;

    bool book[6];

    for (int i = 1; i <= 5; i++)
    {
        int cardnumber;
        cin >> cardnumber;
        player1.push(cardnumber);
    }
    for (int i = 1; i <= 5; i++)
    {
        int cardnumber;
        cin >> cardnumber;
        player2.push(cardnumber);
    }
    for (int i = 1; i <= 5; i++)
    {
        book[i] = 0;
    }
    while (!player2.empty() && !player1.empty())
    {
        if (book[player1.front()])
        {
            while (book[player1.front()])
            {
                int card = gamepool.top();
                book[card] = 0;
                gamepool.pop();
                player1.push(card);
            }
        }
        else
        {
            gamepool.push(player1.front());
            book[player1.front()] = 1;
            player1.pop();
        }

        if (book[player2.front()])
        {
            while (book[player2.front()])
            {
                int card = gamepool.top();
                book[card] = 0;
                gamepool.pop();
                player2.push(card);
            }
        }
        else
        {
            gamepool.push(player2.front());
            book[player2.front()] = 1;
            player2.pop();
        }
    }
    if (player2.empty())
        cout << "player1 win" << endl;
    if (player1.empty())
        cout << "player2 win" << endl;
}

// int main()
// {
//     Solution();
//     return 0;
// }